package com.nanyang.tms.controller.company;

import javax.validation.Valid;

import com.nanyang.tms.api.dto.response.companystored.CompanyStoredAmountResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.companystored.CompanyStoredQueryRequest;
import com.nanyang.tms.api.dto.request.companystored.CompanyStoredUpdateStateRequest;
import com.nanyang.tms.api.dto.response.companystored.CompanyStoredResponse;
import com.nanyang.tms.api.service.companystored.CompanyStoredRpcService;


@RestController
@RequestMapping("/companystored")
public class CompanyStoredController {
    @Reference(version = "1.0.0", timeout = 10000, check = false)
    private CompanyStoredRpcService companyStoredRpcService;
    /**
     * <p>listCompanyStored</p>
     * <p>Description:客户储值信息列表</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResult<PageBean<CompanyStoredResponse>> listCompanyStored(@RequestBody CompanyStoredQueryRequest param) {
        ApiResult<PageBean<CompanyStoredResponse>> apiResult = companyStoredRpcService.listCompanyStored(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * <p>listCompanyStored</p>
     * <p>Description:查询根据编码</p>
     *
     * @param companyCode
     * @return
     */
    @RequestMapping(value = "/selectByCode/{companyCode}", method = RequestMethod.GET)
    public ApiResult<CompanyStoredResponse> selectByCode(@PathVariable("companyCode") String companyCode) {
        ApiResult<CompanyStoredResponse> apiResult = companyStoredRpcService.selectByCode(companyCode);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 禁用
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/disable", method = RequestMethod.POST)
    public ApiResult<Boolean> disableState(@BindParam @RequestBody @Valid CompanyStoredUpdateStateRequest param) {
        ApiResult<Boolean> apiResult = companyStoredRpcService.disableState(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 启用
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/enable", method = RequestMethod.POST)
    public ApiResult<Boolean> enableState(@BindParam @RequestBody @Valid CompanyStoredUpdateStateRequest param) {
        ApiResult<Boolean> apiResult = companyStoredRpcService.enableState(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * <p>storedInfo</p>
     * <p>Description:查询根据编码</p>
     *
     * @param companyCode
     * @return
     */
    @BindParam
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public ApiResult<CompanyStoredAmountResponse> storedInfo(@Value("") @BindParam String companyCode) {
        ApiResult<CompanyStoredAmountResponse> apiResult = companyStoredRpcService.storedInfo(companyCode);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
}
